package com.jiyun.controller;


import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.jiyun.pojo.DcCancelorder;
import com.jiyun.service.IDcCancelorderService;
import com.jiyun.utils.R;
import com.jiyun.utils.Result;
import jakarta.servlet.http.HttpServletRequest;
import org.aspectj.weaver.Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.concurrent.TimeUnit;

/**
 * <p>
 * 取消订单表 前端控制器
 * </p>
 *
 * @author author
 * @since 2024-11-26
 */
@RestController
@RequestMapping("/cancelorder")
public class DcCancelorderController {
    @Autowired
    private IDcCancelorderService dcCancelorderService;
    @Autowired
    private RedisTemplate redisTemplate;
    @RequestMapping("/change")
    public R change(@RequestBody DcCancelorder dcCancelorder){
        System.out.println("----------------"+dcCancelorder);
        String path = (String) redisTemplate.opsForValue().get("path");
        dcCancelorder.setFileList(path);
        System.out.println("path:"+path);
        if (StrUtil.isBlank(dcCancelorder.getFileList())){
            return R.error().message("图片不能为空");
        }
        dcCancelorderService.save(dcCancelorder);
        return R.ok().message("取消成功");
    }
    @PostMapping("/fileUpload")
    public Result upload(MultipartFile file) {
        String path= dcCancelorderService.savefile(file);
        redisTemplate.opsForValue().set("path",path,1, TimeUnit.MINUTES);
        return Result.ok(path);
    }
}
